package logic

import (
	"context"
	"doctor/doctorrpc/doctorrpc"
	"doctor/doctorrpc/internal/svc"
	"doctor/doctorrpc/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *AddLogic) Add(in *doctorrpc.AddRequest) (*doctorrpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	doctor := mysql.Doctor{
		Name:    in.Name,
		Age:     in.Age,
		Sex:     in.Sex,
		Address: in.Address,
	}
	mysql.DB.Create(&doctor)
	return &doctorrpc.AddResponse{
		Id: int64(doctor.ID),
	}, nil
}
